<!--
 * @Author: @Edwin
 * @Date: 2020-12-20 10:25:23
 * @LastEditors: Please set LastEditors
 * @LastEditTime: 2021-12-06 09:41:45
 * @FilePath: \cang-chu-guan-li-xi-tong\src\components\common\stockManagement.vue
-->
<!-- 
所有页面的生成单据信息的组件

接受参数: 
对话框标题
单据表格列
物品表格列
原单名称: 如销售原单、采购原单等


返回的参数: 原单数据

-->
<template>
  <div>
    <a-button type="primary" @click="showModal">
      <a-icon type="plus" />
      根据源单生成
    </a-button>

    <a-modal
      :visible="visible"
      @ok="handleOk"
      @cancel="handleCancel"
      width="70%"
    >
      <a-tabs defaultActiveKey="1" @change="changepage">
        <a-tab-pane tab="采购订单生成采购入库" key="1">
          <a-form v-bind="layout">
            <a-row>
              <a-col :xl="8" :lg="8" :md="8" :sm="24" :xs="24">
                <a-form-item label="时间期间">
                  <a-range-picker
                    v-model="searchForm.rangeDate"
                    @change="getRangeTime"
                  />
                </a-form-item>
              </a-col>
              <a-col :xl="8" :lg="8" :md="8" :sm="24" :xs="24">
                <a-form-item label="单据状态">
                  <a-select
                    v-model="searchForm.documentClosed"
                    style="width: 100%"
                  >
                    <a-select-option
                      v-for="item in documentClosedList"
                      :key="item"
                      :value="item"
                    >
                      {{ item }}
                    </a-select-option>
                  </a-select>
                </a-form-item>
              </a-col>
              <a-col :xl="8" :lg="8" :md="8" :sm="24" :xs="24">
                <a-form-item label="订单编号">
                  <a-select
                    v-model="searchForm.orderNumb"
                    style="width: 100%"
                    @search="handleSearch"
                    showSearch
                  >
                    <a-select-option
                      v-for="item in SourceOrderList"
                      :key="item"
                      :value="item"
                    >
                      {{ item }}
                    </a-select-option>
                  </a-select>
                </a-form-item>
              </a-col>
            </a-row>
            <a-row>
              <a-col :xl="8" :lg="8" :md="8" :sm="24" :xs="24">
                <a-form-item label="供应商">
                  <a-select
                    v-model="searchForm.supplier_text"
                    @change="getfarmerId"
                    @search="getAllfarmerList"
                    showSearch
                    style="width: 100%"
                  >
                    <a-select-option
                      v-for="item in supplierList"
                      :key="item.id"
                      :value="item.No + '|' + item.name + '|' + item.id"
                    >
                      {{ item.No }} {{ item.name }}
                    </a-select-option>
                  </a-select>
                </a-form-item>
              </a-col>
              <a-col :xl="8" :lg="8" :md="8" :sm="24" :xs="24">
                <a-form-item label="采购部门">
                  <a-tree-select
                    v-model="searchForm.ownedBranch"
                    show-search
                    style="width: 100%"
                    :tree-data="depTree"
                    allow-clear
                    :replace-fields="replaceFields"
                  ></a-tree-select>
                </a-form-item>
              </a-col>
              <a-col
                :xl="8"
                :lg="8"
                :md="8"
                :sm="24"
                :xs="24"
                :style="{ textAlign: 'right' }"
              >
                <a-button type="primary" @click="Search()">查询</a-button>
                <a-button style="margin-left: 8px" @click="Reset()"
                  >重置</a-button
                >
              </a-col>
            </a-row>
          </a-form>
          <!-- orderColumns  上半部分
listColumns 下半部分 -->
          <!-- 根据源单生产上半部分交互 -->
          <a-table
            style="margin-top: 20px"
            :columns="orderColumns"
            :scroll="{ x: 1000 }"
            :data-source="orderDataSource"
            @change="handleTableChange"
            :pagination="pagination"
            :row-selection="{
              selectedRowKeys: orderSelectedRowKeys,
              onChange: orderOnSelectChange,
              type: 'radio',
              getCheckboxProps: getCheckboxProps,
            }"
          >
            <!-- 审核标志 -->
            <span slot="documentClosed" slot-scope="text, record">
              <a-popconfirm
                title="是否关闭单据?"
                v-if="record.documentClosed == '开启'"
                @confirm="Giorto(record, 1)"
              >
                <a> {{ text }} </a>
              </a-popconfirm>
              <a-popconfirm
                title="是否开启单据?"
                v-if="record.documentClosed == '关闭'"
                @confirm="Giorto(record, 1)"
              >
                <a> {{ text }} </a>
              </a-popconfirm>
            </span>
          </a-table>

          <!-- 下班部分表格 -->
          <a-table
            style="margin-top: 10px"
            :columns="listColumns"
            :data-source="ListDataSource"
            :scroll="{ x: 1500 }"
            :row-selection="{
              selectedRowKeys: listSelectedRowKeys,
              onChange: listOnSelectChange,
              getCheckboxProps: getCheckboxProps,
            }"
          >
            <!-- 审核标志 -->
            <span slot="documentClosed" slot-scope="text, record">
              <a-popconfirm
                title="是否关闭单据?"
                v-if="record.documentClosed == '开启'"
                @confirm="Giorto(record, 2)"
              >
                <a> {{ text }} </a>
              </a-popconfirm>
              <a-popconfirm
                title="是否开启单据?"
                v-if="record.documentClosed == '关闭'"
                @confirm="Giorto(record, 2)"
              >
                <a> {{ text }} </a>
              </a-popconfirm>
            </span>
          </a-table>
        </a-tab-pane>
        <a-tab-pane tab="外购入库生成采购入库" key="2" forceRender>
          <a-form-model :model="form_search" v-bind="layout">
            <a-row>
              <a-col :xl="6" :md="6" :lg="12" :sm="24" :xs="24">
                <a-form-model-item label="订单编号">
                  <a-input v-model="form_search.document" />
                </a-form-model-item>
              </a-col>

              <a-col :xl="6" :md="6" :lg="12" :sm="24" :xs="24">
                <a-form-model-item label="进货单位">
                  <a-input v-model="form_search.purchasingUnit"></a-input>
                </a-form-model-item>
              </a-col>
              <a-col :xl="6" :md="6" :lg="12" :sm="24" :xs="24">
                <a-form-model-item
                  ref="document_date"
                  label="日期"
                  prop="document_date"
                >
                  <a-date-picker
                    v-model="form_search.day"
                    type="date"
                    placeholder="年/月/日 "
                    style="width: 100%"
                  />
                </a-form-model-item>
              </a-col>

              <a-col :xl="6" :md="6" :lg="12" :sm="24" :xs="24">
                <a-button
                  type="primary"
                  style="margin-left: 30%"
                  @click="getSearch"
                  >查询</a-button
                >
                <a-button type="primary" style="margin-left: 2%" @click="Reset1"
                  >重置</a-button
                >
              </a-col>
            </a-row>
            <a-table
              style="margin-top: 10px"
              :columns="headColumns"
              :data-source="closeOrderDataSource"
              :pagination="pagination1"
              @change="handleTableChange1"
              :row-selection="{
                selectedRowKeys: orderSelectedRowKeys1,
                type: 'radio',
                onChange: orderOnSelectChange1,
              }"
            >
            </a-table>
            <a-table
              style="margin-top: 10px"
              :columns="columns"
              :data-source="data_Source"
              :row-selection="{
                selectedRowKeys: listSelectedRowKeys1,
                onChange: listOnSelectChange1,
              }"
            >
            </a-table>
          </a-form-model>
        </a-tab-pane>
      </a-tabs>

      <!-- 搜索表单---查询条件 -->
    </a-modal>
  </div>
</template>

<script>
import { CommonAjax } from "@/services/modules/common";
const comHttp = new CommonAjax(); // 公用接口
//采购入库页面
import { CaiGouRuKuHttp } from "@/services/modules/RuKuGuGuanLi/CaiGouRuKu";
const cgrkHttp = new CaiGouRuKuHttp(); // 采购入库
import moment from "moment";
const columns = [
  {
    title: "序号",
    dataIndex: "key",
    align: "center",
    fixed: "left",
    width: "100px",
  },
  {
    title: "存货编码",
    dataIndex: "inventoryNo",
    align: "center",
  },
  {
    title: "存货名称",
    dataIndex: "inventoryName",
    key: "inventoryName",
    align: "center",
  },
  {
    title: "规格",
    dataIndex: "specifications",
    align: "center",
  },
  {
    title: "单位",
    dataIndex: "unit",
    align: "center",
  },
  {
    title: "辅助计量单位",
    dataIndex: "auxiliaryUnitOfMeasurement",
    align: "center",
    scopedSlots: { customRender: "auxiliaryUnitOfMeasurement" },
  },
  {
    title: "单价",
    dataIndex: "unitPrice",
    key: "unitPrice",
    align: "center",
    scopedSlots: { customRender: "unitPrice" },
  },
  {
    title: "购入数量",
    dataIndex: "purchaseQuantity",
    align: "center",
    scopedSlots: { customRender: "purchaseQuantity" },
  },
  {
    title: "金额",
    dataIndex: "amountOfMoney",
    align: "center",
    scopedSlots: { customRender: "amountOfMoney" },
  },
  {
    title: "交货日期",
    dataIndex: "deliveryDate",
    align: "center",
  },
];
const headColumns = [
  //外购订单

  {
    title: "序号",
    dataIndex: "key",
    align: "center",
    scopedSlots: { customRender: "key" },
  },
  {
    title: "订单编号",
    dataIndex: "document",
    align: "center",
    scopedSlots: { customRender: "document" },
  },
  {
    title: "进货单位",
    dataIndex: "purchasingUnit",
    align: "center",
    scopedSlots: { customRender: "purchasingUnit" },
  },
  {
    title: "地区",
    dataIndex: "region",
    align: "center",
    scopedSlots: { customRender: "region" },
  },
  {
    title: "日期",
    dataIndex: "day",
    align: "center",
    scopedSlots: { customRender: "day" },
  },
  {
    title: "操作",
    dataIndex: "operation",
    align: "center",
    scopedSlots: { customRender: "operation" },
  },
];

export default {
  props: {
    // 表单列
    orderColumns: {
      type: Array,
      required: true,
    },
    // 列表列
    listColumns: {
      type: Array,
      required: true,
    },
  },

  data() {
    return {
      page: "",
      pagination1: {
        total: 0,
        current: 1,
        pageSize: 5, //每页中显示10条数据
        showSizeChanger: true,
        pageSizeOptions: ["5"], //每页中显示的数据
        showTotal: (total) => `共有${total}条数据`, //分页中显示总的数据
      },
      closeOrderDataSource: [], //外购订单数据
      columns,
      headColumns,
      replaceFields: {
        children: "syncDepartmentFilesEntityList",
        title: "deptname",
        value: "pkDeptdoc",
      },
      form_search: {
        document: "",
        purchasingUnit: "",
        day: null,
      },
      visible: false,

      searchForm: {
        startTime: "", // 开始日期
        endTime: "", // 结束日期
        ownedBranch: "",
        supplier: "",
        supplier_text: "", //供应商
        orderNumb: "",
        rangeDate: null, // 时间范围
        departmentName: "",
        departmentId: "",
        documentClosed: "开启", //单据状态
        // 采购入库单提报部门
        reportDept: "", // 部门名称
        departmentNo: "", // 部门编号
      },
      pagination: {
        total: 0,
        current: 1,
        pageSize: 5, //每页中显示5条数据
        showSizeChanger: true,
        pageSizeOptions: ["5"], //每页中显示的数据
        showTotal: (total) => `共有${total}条数据`, //分页中显示总的数据
      },

      layout: {
        labelCol: { span: 5 },
        wrapperCol: { span: 15 },
      },

      // 订单左侧选择框
      orderSelectedRowKeys: [], // 订单选择
      orderSelectedRowKeys1: [], // 订单选择

      // orderDataSource: [{ key: 1 }],
      orderDataSource: [],

      // 列表左侧选择框
      listSelectedRowKeys: [], // 列表选择
      listSelectedRowKeys1: [],
      ListDataSource: [],
      SourceOrderList: [], //源单单号列表

      data_Source: [],
      startTime: "", // 开始时间
      endTime: "", // 结束时间
      queryParam: {
        //查询参数
        page: 1, //第几页
        size: 5, //每页中显示数据的条数
        hosName: "",
        hosCode: "",
        province: "",
        city: "",
      },
      stockNoticeShowType: false,
      deparmentList: [], // 部门列表
      documentClosedList: ["开启", "关闭"],
      SelectData: [], // 选中的值
      originData: [], //采购订单表格
      originData3: [], //外购订单表格
      originData2: [], //采购订单表头
      originData4: [], //外购订单表头
      supplierList: [], // 供应商
      depTree: [], // 部门列表
      queryCache: "",

      savesourceNumber: "", //保存源单号
      saveinventoryId: "", //保存存货id

      saveidfor_open_down: "",
      idForinf: "",
    };
  },
  mounted() {
    this.getPurchaseStorageList(); //获取采购订单列表
    this.getDeparmentTreeBelong();
    this.getsalepurchaseorder(); //用于外购订单列表
  },
  methods: {
    changepage(data) {
      this.page = data;
      console.log(this.page);
    },
    /**
     //todo 审核标志-单据关闭功能 
     * @description: 审核标志-单据关闭功能
     * @description: 
     * @return
     */
    moment,
    // 搜索条件的函数
    getSearch() {
      this.resetPagination(); //重置页码和参数

      let queryPath = this.getQueryPath1();
      console.log("当前的查询路径为:::", queryPath);
      this.getsalepurchaseorder(queryPath);
    },
    Search1() {
      // 获取目前选择好的查询条件
      let queryPath = this.getQueryPath1();
      this.getsalepurchaseorder(queryPath);
    },
    // 重置当前页码及页码参数
    resetPagination() {
      this.pagination1 = {
        total: 0,
        current: 1,
        pageSize: 5, //每页中显示10条数据
        showSizeChanger: true,
        pageSizeOptions: ["5"], //每页中显示的数据
        showTotal: (total) => `共有${total}条数据`, //分页中显示总的数据
      };
      //查询参数
      this.queryParam = {
        //查询参数
        page: 1, //第几页
        size: 5, //每页中显示数据的条数
      };
    },
    // 获取查询条件
    getQueryPath1() {
      let queryPath = "";
      queryPath =
        "?pageNo=" +
        this.queryParam.page +
        "&document=" +
        this.form_search.document +
        "&purchasingUnit=" +
        this.form_search.purchasingUnit +
        "&day=" +
        moment(this.form_search.day).format("YYYY-MM-DD");
      // "&status=审核通过";

      console.log(" this.form_search.day ", this.form_search.day);

      return queryPath; // 返回的查询条件
    },
    getsalepurchaseorder(queryPath = "?pageNo=1") {
      console.log("外购订单列表");
      this.closeOrderDataSource = [];
      // queryPath = queryPath + "&status=审核通过";
      cgrkHttp.getsalepurchaseorder(queryPath).then((res) => {
        console.log("用于外购订单列表", res);
        const pagination = { ...this.pagination };
        pagination.total = res.result.total;
        this.pagination = pagination;
        if (res && res.success === true) {
          this.closeOrderDataSource = res.result.records;
          console.log("this.closeOrderDataSource", this.closeOrderDataSource);
          for (let i = 0; i < res.result.records.length; i++) {
            this.closeOrderDataSource[i].key =
              (res.result.current - 1) * 10 + i + 1;
          }
        }
      });
    },
    // 外购订单生成采购入库上面表格的选中事件
    orderOnSelectChange1(selectedRowKeys, selectedRows) {
      this.data_Source = [];
      this.idForinf = selectedRows[0].id;
      this.orderSelectedRowKeys1 = selectedRowKeys;
      this.orderselectedRows = selectedRows;

      this.originData4 = selectedRows;
      // console.log("record", records);
      // orderSelectedRowKeys1
      let id = selectedRows[0].id;
      cgrkHttp.getsalepurchaseorderinfo("?id=" + id).then((res) => {
        console.log("用于外购订单详情", res);
        this.data_Source = res.result.object.list;
        console.log("this.data_Source", this.data_Source);
        for (let i = 0; i < res.result.object.list.length; i++) {
          this.data_Source[i].key = i + 1; //!！！！！
        }
      });
    },
    // 分页函数
    handleTableChange1(pagination) {
      console.log("pagination===========>", pagination);
      this.pagination.current = pagination.current;
      this.pagination.pageSize = pagination.pageSize;
      this.queryParam.page = pagination.current;
      this.queryParam.size = pagination.pageSize;
      this.Search1();
    },
    Giorto(record, select) {
      let that = this;
      console.log(`选中了${select}表格信息`);
      console.log(`选中该记录返回的所有信息:`, record);
      //路线判断
      record.documentClosed === "开启"
        ? goState.call(that, "关闭", record)
        : goState.call(that, "开启", record);

      function goState(status, record) {
        console.log(`正在执行状态${status}功能:::::::::`);
        let data = {
          id: record.id,
          documentClosed: status,
        };
        //接口判断
        return select === 1
          ? this.updatePurchaseaAddorder(data, status)
          : this.updatePurchaseiItemiInformation(data, status);
      }
    },
    //接口关闭-上A
    updatePurchaseaAddorder(data, status) {
      cgrkHttp.updatepurchaseaddorder(data).then((res) => {
        if (!res.success) {
          this.$message.error(res.message);
          return;
        }
        this.$message.success(`${status}成功!`);
        console.log(`Success::::::${status}功能成功执行`);
        this.getPurchaseStorageList(); //获取采购订单列表
      });
    },
    //接口关闭-下
    updatePurchaseiItemiInformation(data) {
      cgrkHttp.updatepurchaseiteminformation(data).then((res) => {
        if (!res.success) {
          this.$message.error(res.message);
          return;
        }
        this.$message.success(`${status}成功!`);
        cgrkHttp
          .getPurchaseStorageInfo("?orderId=" + this.saveidfor_open_down)
          .then((res) => {
            this.ListDataSource = res.result;
          });
      });
    },

    // 表格选择事件,
    // rain-fix:
    // 采购订单生成采购入库单 上面表格的选中事件
    orderOnSelectChange(selectedRowKeys, selectedRows) {
      //用于审核标志
      this.saveidfor_open_down = selectedRows[0].id;

      this.ListDataSource = [];
      this.orderSelectedRowKeys = selectedRowKeys;
      this.orderselectedRows = selectedRows;
      // console.log("selectedRowKeys changed: ", selectedRowKeys);
      console.log("selectedRows changed: ", selectedRows); //获取表格中一行数据
      this.savesourceNumber = selectedRows[0].orderNum;
      this.originData2 = selectedRows;
      console.log("this.originData2", this.originData2);

      let id = selectedRows[0].id;
      cgrkHttp.getPurchaseStorageInfo("?orderId=" + id).then((res) => {
        console.log("采购入库根据源单生成表格选择事件res", res);
        let _data = res.result;
        _data.forEach((item, index) => {
          item.key = index + 1;
          item.orderNum = selectedRows[0].orderNum;
        });
        this.ListDataSource = _data;
      });
    },
    // 下面的列表选择事件 rain:fix 重新进行直接赋值
    listOnSelectChange(selectedRowKeys, selectedRows) {
      // console.log("selectedRowKeys changed: ", selectedRowKeys);
      console.log("下面的表格 selectedRows changed: ", selectedRows); //选中的数据

      // this.saveinventoryId = selectedRows[0].inventoryId;
      this.listSelectedRowKeys = selectedRowKeys;

      this.originData = [];
      for (let i = 0; i < selectedRows.length; i++) {
        this.originData.push(selectedRows[i]);
      }
    },
    listOnSelectChange1(selectedRowKeys, selectedRows) {
      // console.log("selectedRowKeys changed: ", selectedRowKeys);
      console.log("下面的表格 selectedRows changed: ", selectedRows); //选中的数据

      // this.saveinventoryId = selectedRows[0].inventoryId;
      this.listSelectedRowKeys1 = selectedRowKeys;

      this.originData3 = [];
      for (let i = 0; i < selectedRows.length; i++) {
        this.originData3.push(selectedRows[i]);
      }
      console.log(" this.originData3", this.originData3);
    },
    // ---------- 公用函数 ----------
    // 时间段
    getRangeTime(date, dateString) {
      console.log(date);
      this.searchForm.startTime = dateString[0];
      this.searchForm.endTime = dateString[1];
    },

    // 搜索
    Search() {
      let queryPath = this.getQueryPath();
      this.getPurchaseStorageList(queryPath);
      console.log("查询条件为:::", queryPath);
    },
    /* Search() {
      let query = "";
      let { orderNumb, supplier, ownedBranch } = this.searchForm;

      
      if (this.startTime) {
        query += `&beginDate=${this.startTime}`;
      }
      if (this.endTime) {
        query += `&endDate=${this.endTime}`;
      }

      if (orderNumb) {
        query += `&orderNumb=${orderNumb}`;
      }
      if (supplier) {
        query += `&supplierId=${supplier}`;
      }
      if (ownedBranch) {
        query += `&cdeptid=${ownedBranch}`;
      }

      query += `&documentClosed=${this.searchForm.documentClosed}`;
      this.queryCache = query;
      this.pagination.current = 1;
      this.pagination.total = 0;
      this.pagination.pageSize = 5;
      this.getPurchaseStorageList(query);
    }, */
    // 获取全局查询条件
    getQueryPath() {
      console.log(this.searchForm);
      let queryPath =
        "?pageNo=" +
        this.queryParam.page +
        "&pageSize=5" +
        "&beginDate=" +
        this.searchForm.startTime +
        "&endDate=" +
        this.searchForm.endTime +
        "&documentClosed=" +
        this.searchForm.documentClosed;
      // 订单编号
      queryPath += this.searchForm.orderNumb
        ? `&orderNumb=${this.searchForm.orderNumb}`
        : "";

      // 客户
      queryPath += this.searchForm.supplier
        ? `&supplierId=${this.searchForm.supplier}`
        : "";

      queryPath += this.searchForm.ownedBranch
        ? `&cdeptid=${this.searchForm.ownedBranch}`
        : "";

      return queryPath; // 返回的查询条件
    },
    // 分页函数
    handleTableChange(pagination) {
      this.pagination.current = pagination.current;
      this.pagination.pageSize = pagination.pageSize;
      this.queryParam.page = pagination.current;
      this.queryParam.size = pagination.pageSize;
      let queryPath = this.getQueryPath();
      this.getPurchaseStorageList(queryPath);
    },

    // 重置
    // 重置
    Reset() {
      this.queryCache = "";
      this.pagination.current = 1;
      this.pagination.total = 0;
      this.pagination.pageSize = 5;
      // this.searchForm = {}; // 重置查询条件
      // this.searchForm.documentClosed = "开启";
      this.searchForm = {
        startTime: "", // 开始日期
        endTime: "", // 结束日期
        ownedBranch: "",
        orderNumb: "",
        supplier: "",
        rangeDate: "", // 时间范围
        departmentName: "",
        departmentId: "",
        documentClosed: "开启", //单据状态
        // 采购入库单提报部门
        reportDept: "", // 部门名称
        departmentNo: "", // 部门编号
      };
      this.SourceOrderList = [];
      this.getPurchaseStorageList(); // 重置销售订单
      this.listDataSource = []; // 重置物品数据
      this.listSelectedRowKeys = []; // 重置选择框中选中的值
      this.orderSelectedRowKeys = [];
    },
    Reset1() {
      this.getsalepurchaseorder();
      this.form_search = {
        document: "",
        purchasingUnit: "",
        day: null,
      };
      this.listSelectedRowKeys1 = []; // 重置选择框中选中的值
      this.orderSelectedRowKeys1 = [];
    },
    // 获取采购入库单列表
    // rain-fix:重新进行修改进行多获取
    // rain-fix:删除手动分页
    getPurchaseStorageList(
      queryPath = "?pageNo=1&pageSize=5&documentClosed=开启"
    ) {
      cgrkHttp.getPurchaseStorageList(queryPath).then((res) => {
        this.orderDataSource = [];
        const pagination = { ...this.pagination };
        pagination.total = res.result.total;
        pagination.pageSize = res.result.size;
        this.pagination = pagination;

        const startIndex =
          (this.pagination.current - 1) * this.pagination.pageSize;
        for (let i = 0; i < res.result.records.length; i++) {
          let data = {
            key: i + 1 + startIndex,
            id: res.result.records[i].id,
            buyer: res.result.records[i].buyer, //采购员id
            buyer_dictText: res.result.records[i].buyer_dictText, //采购员
            orderNum: res.result.records[i].orderNumb, // 订单编号
            cdeptid: res.result.records[i].cdeptid, //采购部门id
            cdeptid_dictText: res.result.records[i].cdeptid_dictText, //采购部门
            dateOfPreparation: res.result.records[i].dateOfPreparation, //订单日期
            supplier: res.result.records[i].supplierId_dictText, //供应商
            supplierId: res.result.records[i].supplierId, //供应商id
            cwarehouseid_dictText: res.result.records[i].cwarehouseid_dictText,
            cwarehouseid: res.result.records[i].cwarehouseid,
            pkCalbody_dictText: res.result.records[i].pkCalbody_dictText,
            cbiztype: res.result.records[i].cbiztype,
            cbiztype_dictText: res.result.records[i].cbiztype_dictText,
            documentClosed: res.result.records[i].documentClosed, //审核标志
          };

          this.orderDataSource.push(data);
        }
      });
    },

    // 展示对话框
    showModal() {
      console.log("");
      this.stockNoticeShowType = true;
      this.getDeparmentTree(); // 获取部门树
      this.getPurchaseStorageList(); //获取采购订单列表
      this.getsalepurchaseorder(); //用于外购订单列表
      this.visible = true;
    },
    // 提交
    handleOk() {
      console.log("提交");

      if (this.page == "2") {
        this.$emit("origin-data3", this.originData3); //将子组件的数据，传递到父组件，下面的表格
        this.$emit("origin-data4", this.originData4); //将子组件的数据，传递到父组件，上面的表格
        this.orderSelectedRowKeys1 = []; //上方table按钮
        this.listSelectedRowKeys1 = []; //下方table按钮
      } else {
        this.$emit("origin-data", this.originData); //将子组件的数据，传递到父组件，下面的表格
        this.$emit("origin-data2", this.originData2); //将子组件的数据，传递到父组件，上面的表格
        this.orderSelectedRowKeys = []; //上方table按钮
        this.listSelectedRowKeys = []; //下方table按钮
      }
      //采购计划生成采购入库单

      //外购计划生成采购入库单

      this.ListDataSource = []; //下方rable重置

      //查现存
      let data = {
        sourceNumber: this.savesourceNumber,
        inventoryId: this.saveinventoryId,
      };
      cgrkHttp.getBalanceInOutStockBySourceNumber(data).then((res) => {
        console.log("现存", res);
        if (res.result) {
          this.$emit("balance", res.result.balance);
        }
      });

      this.visible = false;
      // this.$emit("select-data", this.SelectData);

      // this.visible = false;
      // // console.log("下方物品数据:::", this.ListDataSource);
      // // console.log("下方表格数据筛选结果:::", this.listSelectedRowKeys);

      // // !!!!! 筛选出选中的数据
      // let goodsLists = [];
      // for (let i = 0; i < this.listSelectedRowKeys.length; i++) {
      //   let target = this.ListDataSource.filter(
      //     (item) => item.key === this.listSelectedRowKeys[i]
      //   )[0];
      //   goodsLists.push(target);
      // }
      // console.log("筛选的选中数据，要传递给父组件::::", goodsLists);
    },
    // 清空
    Empty() {
      // this.ListDataSource = [];
      console.log("清空");
    },
    // 取消
    handleCancel() {
      this.Reset();
      // this.$emit("origin-data", this.originData); //将子组件的数据，传递到父组件
      this.visible = false;
    },

    // 根据业务需求,自己添加相应的样式和函数
    // 部门按钮触发
    DepartmentChange(value, option) {
      this.searchForm.departmentId = option.key;
    },

    // 获取销售订单列表

    // ----------- 用于备货通知单独有的 -----------
    // 获取部门列表
    getDeparmentTree() {
      comHttp.getDepartmentList().then((res) => {
        // let tree = this.resetTree(res.result);
        // console.log("获取部门树::::",tree);
        this.deparmentList = res.result;
        this.resetTree(this.deparmentList);
      });
    },
    // 树节点的 value值 变成 title,为了加上搜索框.
    resetTree(Tree) {
      Tree.forEach((item) => {
        item.value = item.title;
        if (item.children) {
          this.resetTree(item.children);
        }
      });
    },
    // 部门下拉框选择
    changeTreeNode(value, label, extra) {
      this.searchForm.departmentNo = extra.triggerNode.eventKey;
      console.log("选择的值::::", this.searchForm.departmentNo);
    },
    // 获取备货通知单列表
    getStockNoticeList() {
      console.log("获取当前备货通知单列表:::");
    },

    //禁止选择的组件
    getCheckboxProps(record) {
      return {
        props: {
          disabled: record.documentClosed === "关闭",
        },
      };
    },
    // 采购订单编号模糊查询
    debounce(value, wait) {
      if (this.timeout) clearTimeout(this.timeout);
      this.timeout = setTimeout(() => {
        this.onfunc(value);
      }, wait);
    },
    handleSearch(value) {
      this.debounce(value, 500);
    },

    onfunc(value) {
      console.log(value);
      console.log("// 采购订单编号模糊查询");
      if (value.match(/^[ ]*$/)) {
        console.log("字符串为空或全空格");
      } else {
        console.log("value", value);
        let query = "?queryNumber=" + value;
        if (value == "" || value == null) {
          this.SourceOrderList = [];
        } else {
          comHttp.getpurchaseorderNo(query).then((res) => {
            this.SourceOrderList = [];
            for (let i = 0; i < res.result.length; i++) {
              this.SourceOrderList.push(res.result[i]);
            }
            console.log(" 采购订单编号", res);
          });
        }
      }
    },

    // getSourceOrderList() {
    //   comHttp.getAllSourceNumber().then((res) => {
    //     console.log("获取采购源单列表:::::", res);
    //     for (let i = 0; i < res.result.length; i++) {
    //       this.SourceOrderList.push(res.result[i]);
    //     }
    //   });
    // },
    getAllfarmerList(value) {
      if (value != "") {
        comHttp
          .queryByLikeName("?customerName=" + value + "&custflag=1,3")
          .then((res) => {
            this.supplierList = [];
            console.log("所有的供应商信息::::", res);
            for (let i = 0; i < res.result.list.length; i++) {
              let data = {
                No: res.result.list[i].custcode, //编号
                id: res.result.list[i].pkCumandoc,
                name: res.result.list[i].custname,
              };

              this.supplierList.push(data);
            }
          });
        console.log("this.supplierList", this.supplierList);
      }
    },
    // 获取供应商change列表
    getfarmerId(value, options) {
      console.log("供应商::::", value, options.key);
      let array = value.split("|");
      console.log("array", array);
      this.searchForm.supplier = array[2];
      this.searchForm.supplier_text = array[1];
    },
    // 获取部门列表
    getDeparmentTreeBelong() {
      comHttp.getDepartmentList().then((res) => {
        this.depTree = res.result;
        console.log("获取部门列表hanshu===", this.depTree);
      });
    },
  },
};
</script>

<style></style>
